package com.dy.placeOrder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dy.placeOrder.Collection;
import com.dy.placeOrder.service.CollectionService;
import com.dy.placeOrder.mapper.CollectionMapper;
import com.dy.placeOrder.util.SensitiveFilter;
import com.dy.placeOrder2.mapper.GoodsMapper;

import com.dy.pojo.Goods;
import com.dy.placeOrder2.mapper.OrdersMapper;
import com.dy.placeOrder2.service.OrdersService;
import com.dy.pojo.Orders;
import com.kaoshi.common.config.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 001
 * @description 针对表【collection】的数据库操作Service实现
 * @createDate 2024-12-02 16:58:32
 */
@Service
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collection>
        implements CollectionService {
    @Autowired
    private CollectionMapper collectionMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    private OrdersMapper ordersMapper;

    @Override
    public Result getCollectionOrders(Integer uid) {
        ArrayList<Integer> ids = new ArrayList<>();
        LambdaQueryWrapper<Collection> qr = new LambdaQueryWrapper<>();
        qr.eq(Collection::getUid, uid);
        List<Collection> list = baseMapper.selectList(qr);
        System.out.println("list:" + list);
        for (Collection collection : list) {
            ids.add(collection.getGid());
        }
        System.out.println("ids:" + ids);
        List<Goods> goods = goodsMapper.selectBatchIds(ids);
        System.out.println("goods:" + goods);
        String s = "收藏";

        return Result.ok(goods);
    }

    @Override
    public Boolean findCollection(Integer uid, Integer gid) {
        LambdaQueryWrapper<Collection> qr = new LambdaQueryWrapper<>();
        qr.eq(Collection::getUid, uid).eq(Collection::getGid, gid);
        if (baseMapper.selectOne(qr) == null){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public void cancel(Integer uid, Integer gid) {
        LambdaQueryWrapper<Collection> qr = new LambdaQueryWrapper<>();
        qr.eq(Collection::getUid, uid).eq(Collection::getGid, gid);
        if (baseMapper.selectOne(qr) != null){
            Collection collection = collectionMapper.selectOne(qr);
            collectionMapper.deleteById(collection.getId());
        }else {
            System.out.println("取消收藏失败");
        }
    }

    @Override
    public void collection(Integer uid, Integer gid) {
        Collection collection = new Collection();
        collection.setUid(uid);
        collection.setGid(gid);
        collectionMapper.insert(collection);
    }
}




